

/**
 * 使用 va_start 、 va_arg 、 va_end 将所有传入的传输打印出来
*/

#include <stdio.h>
#include <stdarg.h>

struct person
{
    char *name;
    int age;
    char score;
    int id;
};

/**
 * 将所有传入的参数全部打印出来
*/
int push_test(const char *format, ...)
{

    printf("arg1 = %s\n", format);

    va_list p;
    va_start(p, format); // p 指向第一个变参变量

    int i = va_arg(p, int);
    printf("arg2 = %d\n", i);

    struct person per = va_arg(p, struct person);
    printf("arg3 = [.name:%s .age:%d .score:%c .id:%d]\n",
           per.name, per.age, per.score, per.id);

    char c = va_arg(p, int);
    printf("arg4 = %c\n", c);

    char *s = va_arg(p, char *);
    printf("arg5 = %s\n", s);

    double d = va_arg(p, double);
    printf("arg6 = %lf\n", d);

    va_end(p);

    return 0;
}

int main()
{

    struct person per = {"www.100ask.org", 10, 'A', 123};

    push_test("abcd", 123, per, 'c', "Hello", 2.79);

    return 0;
}